package cyy.example.com.facotry.data.center;

import com.example.com.common.utils.L;

import java.util.Arrays;

import cyy.example.com.facotry.model.db.MessageModle;
import cyy.example.com.facotry.net.helper.DbHelper;


/**
 * Created by ChenYiYao on 2018/12/3.
 * des :  消息模块数据处理类
 */
public class MessageDispatcher implements MessageCenter {

    private static MessageCenter instance;

    public static MessageCenter instance() {
        if (instance == null) {
            synchronized (MessageCenter.class) {
                if (instance == null)
                    instance = new MessageDispatcher();
            }
        }
        return instance;
    }

    @Override
    public void dispatch(MessageModle... modles) {
        if (modles == null || modles.length < 1) return;
        if (modles.length == 1) {
            boolean b = DbHelper.getInstance().saveObject(MessageModle.class,modles[0]);
            L.d("数据插入成功：" + b);
        } else {
            boolean b = DbHelper.getInstance().saveMultObject(MessageModle.class,Arrays.asList(modles));
            L.d("数据插入成功：" + b);
        }
    }


}
